/**
 * Created by kedong on 2016/8/11.
 */
var CryptoJS = require("crypto-js");

/*
 * 加密用的Key 可以用26个字母和数字组成 此处使用AES-128-CBC加密模式，key需要为16位。
 */
var key = CryptoJS.enc.Utf8.parse("youquqwertyuiopa");
var iv = CryptoJS.enc.Utf8.parse('12I9OPQjaC5FlFIl');

/**
 * 加密
 * @param word
 * @returns {string}
 * @constructor
 */
//function Encrypt(word)
var Encrypt = word=> {
    var srcs = CryptoJS.enc.Utf8.parse(word);
    var encrypted = CryptoJS.AES.encrypt(srcs, key, {iv: iv, mode: CryptoJS.mode.CBC});
    return encrypted.toString();
};

/**
 * 解密
 * @param word
 * @returns {string}
 * @constructor
 */
//function Decrypt(word)
var Decrypt = word=> {
    var decrypt = CryptoJS.AES.decrypt(word, key, {iv: iv, mode: CryptoJS.mode.CBC});
    return CryptoJS.enc.Utf8.stringify(decrypt).toString();
};

module.exports = {
    Decrypt, Encrypt
};